class Solution {
    public int minCostClimbingStairs(int[] cost) {
        int costLen = cost.length;
        int dp[] = new int[costLen];
        dp[0] = cost[0];
        dp[1] = cost[1];
        int min = Math.min(cost[0], cost[1]);
        for (int i = 2; i < costLen; i++) {
            dp[i] = Math.min(dp[i - 1] + cost[i], dp[i - 2] + cost[i]);
            if (i == costLen-1) {
                min = Math.min(dp[i], dp[i - 1]);
            }
        }
        return min;
    }
}